<?php


namespace App\Model;

use EasySwoole\EasySwoole\Config;

class Wechat
{

    private $client;

    /**
     * Wechat constructor.
     */
    public function __construct()
    {
        $config = Config::getInstance()->getConf('WECHAT.officialAccount');
        $this->client = new \EasySwoole\WeChat\WeChat(); // 创建一个实例
        $this->client->config()->setTempDir(EASYSWOOLE_TEMP_DIR); // 指定全局临时目录
        $this->client->officialAccount()->getConfig()
            ->setAppId($config['appId'])
            ->setAppSecret($config['appSecret']);
    }

    public function GetClient()
    {
        $token = $this->client->officialAccount()->accessToken()->getToken();
        $this->client->officialAccount()->getConfig()->setToken($token);
        return $this->client;
    }
}